﻿using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

using com.fly.sms;

namespace com.fly.sms
{
    public class SendNumberPoolAction:BaseAction
    {
        public SendNumberPoolAction(HttpContext contextTemp)
        {
            this.context = contextTemp;
        }
        public override void excute()
        {
            string Name=context.Request["Name"];
            string MsgContent=context.Request["MsgContent"];
            string CustomerNumberPoolId = context.Request["CustomerNumberPoolId"];

            //获取号码池号码
            string[] DestNumberArray = CustomerNumberPoolDetailService.findByNumberPoolId(CustomerNumberPoolId);

            int msgLength=MsgContent.Length;
            int msgCount = 1;
            if (msgLength>70)
            {
                if (msgLength % 65 == 0)
                {
                    msgCount = msgLength / 65;
                }
                else {
                    msgCount = msgLength / 65 + 1;
                }
            }
            //string[] DestNumberArray=DestNumber.Split(new Char[] { ';' });

            //添加待发送短信
            //string msgId = StringUtil.GetOID();

            bool rst = SMSendService.add(guid, guid, CustomerId, null, Name, MsgContent, msgCount * DestNumberArray.Length, DestNumberArray.Length);
            //或缺添加后的Id
            //string msgId = SMSendService.getId(Name);
            foreach (string DestNumber in DestNumberArray)
            {
                SMSendDetailService.add(guid, DestNumber, msgCount);
            }
            ht.Add("responseCode", "200");
            ht.Add("responseData", rst);
            string json2 = JsonConvert.SerializeObject(ht);
            context.Response.Write(json2);           
        }
    }
}